home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: automatic charrs
- Date: 26 Feb 1996 16:56:24 GMT
- Organization: OpenVision
- Message-ID: <4gsono$3uc@spanky.pls.ov.com>
- References: <4glp29$dsh@d2.tufts.edu>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article dsh@d2.tufts.edu, rdorich@emerald.tufts.edu (Roberto Dorich) writes:
- >Hello,
- >
- >Could someone enlighten me, and tell me why the following program runs
- >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
- >
- >#include <stdio.h>
- >char *b() { return "Hello";}
- ^^^^^^^
- This string should be defined as const, which means that you cannot
- modify it. Apparently gcc is enforcing this, and Sun's cc is not.
-
- Fletcher.Glenn@ov.com
-
- >
- >main() {
- > char *a=b();
- >
- > a[0]='X';
- > printf("--> %s\n",a);
- >}
- >
- >Esentially, gcc puts out the following assembly code:
- >
- >call b,0
- >nop
- >mov 88,%o1 // %o1 = 'X'
- >stb %o1, [%o0] // a[0] = %o1
- >
- >And cc spits out the following:
- >
- > call b
- > nop
- > mov 88,%l1
- > stb %l1,[%l0+0]
- >
- >(this assembly code has been optimized by me :-/ )
- >
- >Anyway, there isn't really that much difference... but I get a seg fault
- >with gcc. Why?
- >
- >Thanks!
- >
- >Roberto
- >
- >--
- >
- >Roberto Dorich o SKI rdorich@ee.cornell.edu
- >Electrical Engineering /= EXTREME rdorich@tufts.edu
- >Cornell University __/__, dorich@ptc.com
- >----------------------------------------------------------------------
-
-
-
-
-
-